﻿<?php

require_once dirname(__FILE__) . '/PgSQL.php';

define("TABLEQH", "DNQH");
define("DNHOTEL", "dnhotel");

function getDistrict()
{
	$sql='SELECT ten_huyen FROM "'.TABLEQH.'"';
	$dbcon = pg_connect("dbname=".PG_DB." password=".PG_PASS." host=".PG_HOST." user=".PG_USER);
	$query = pg_query($dbcon,$sql);
	echo '<select id="district" name="phuongxa">"';
	echo "<option value='0'></option>";
	while($kq=pg_fetch_assoc($query)) {
	//echo $kq[ten_phuong]."<br>";
	echo "<option value='".$kq['ten_huyen']."'>".$kq['ten_huyen']."</option>";
	}
	echo '</select>';
	pg_close($dbcon);
}
function getInfoHotel($id)
{
	$pg = new PgSQL();
	$pg->connect();
	$sql='SELECT * FROM '.DNHOTEL.' WHERE id='.$id;
	$query = $pg->query($sql);
	if($kq=pg_fetch_assoc($query)) {
	//echo $kq[ten_phuong]."<br>";
	echo '<h4 class="about-title">';
	echo $kq['name'];
	echo '</h4>';
	echo '<div class="hotel-info">';
	echo 'Địa chỉ: '.$kq['address'];
	echo '<br>';
	echo '<img src="images/phone.png" height="20" width="20">'.$kq['phone'];
	echo '<br>';
	echo '<a href="http://'.$kq['website'].'">'.$kq['website'].'</a>';
	echo '<br>';
	if (!empty($kq['star']))
	{
		for ($i=1; $i<=$kq['star']; $i++)
		{
			echo '<img src="images/star.png" height="20" width="20"> ';
		}
	}
	echo '</div>';
	}
	$pg->disconnect();
}

function getComment($id)
{
	$pg = new PgSQL();
	$pg->connect();
	$sql = 'SELECT * FROM comment WHERE id='.$id;
	$data = $pg->query($sql);
	//$data = $db->get_data();
	$html = '';
	if ($pg->numberRows() != 0)
	{
		while ($row = pg_fetch_object($data)) {
			$html .= '<div class="message" >	
				<div class="userInfo">	
					<div class="avatar">
						<img src="images/avatar.png"> 
					</div>	
					<h3 class="userName">
						<em class="userTitle">'.$row->creater.'</em>
					</h3>						
					<span class="arrow"><span></span></span>
				</div>
				<div class="content">										
					<div class="messageContent">		
						'.$row->content.'
					</div>																
					<div class="date">
						'.$row->date.'
					</div>
				</div>
			</div>';
		}
	} else {
		$html = 'Chưa có nhận xét nào về khách sạn này';
	}
	$pg->disconnect();
	echo $html;
}
?>